402C - Searching for Graph - CodeForces Solution


brute force constructive algorithms graphs *1500

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <bitset>

using namespace std;
 
int main(){
	
	int t;cin>>t;
	while(t--){
		int n,p;cin>>n>>p;
		int num=0;
		for(int i=1;i<n;i++){
			for(int j=i+1;j<=n;j++){
				cout<<i<<' '<<j<<endl;
				num++;
				if(num==(2*n+p)){
					i=n;
					break;
				}
			}
		}
	}
}


Comments

Submit
0 Comments
More Questions

Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes